package roma.home.pages;

import java.util.Set;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import roma.home.data.Values;

public class R01HomePage extends AbstractPage {

	public R01HomePage(WebDriver driver) {
		super(driver);
	}
	
	@FindBy(id = "adoption_link") WebElement adoption; 
	@FindBy(id = "about_link") WebElement about; 
	@FindBy(id = "contact_link") WebElement contact;
	@FindBy(xpath = ".//*[@id='table1']/tbody/tr[2]/td[2]/h1") WebElement headerHome;
	@FindBy(tagName = "p") WebElement paragraph;
	@FindBy(tagName = "h1") WebElement headerTerm;
	@FindBy(id = "footer_term") WebElement termLink;
	@FindBy(xpath = ".//*[@id='table1']/tbody/tr[4]/td/a") WebElement outerLink;
	
	
	public void clickAdoptionLink() {
		clickTheLink(adoption);
		checkTitle(Values.ADOPT_TITLE);
	}
	
	public void clickAboutLink() {
		clickTheLink(about);
		checkTitle(Values.ABOUT_TITLE);
	}
	
	public void clickContactLink() {
		clickTheLink(contact);
		checkTitle(Values.CONTACT_TITLE);
	}
	
	public void clickTermLink() {
		String handler = driver.getWindowHandle();
		clickTheLink(termLink);
		Set<String> handlers = driver.getWindowHandles();
		for (String i : handlers) {
			driver.switchTo().window(i);
		}
		checkHeaders(headerTerm, Values.TERM_HEADER);
		checkHeaders(paragraph, Values.TERM_PARAGRAPH);
		driver.close();
		driver.switchTo().window(handler);
	}
	
	public void clickOuterLink() {
		clickTheLink(outerLink);
		checkTitle(Values.OUTER_TITLE);
		getBack();
	}
	
	public void checkHomeHeader() {
		checkHeaders(headerHome, Values.HOME_HEADER);
	}
	
	public void checkHomeParagraph() {
		checkHeaders(paragraph, Values.HOME_PARAGRAPH);
	}
	
}
